<template>
  <div class="app-container">
    <team-information ref="form" :form="form" />
    <player-information ref="table" :init-list="list" />
    <operation-button @reset="handleReset" @submit="handleSubmit" />
  </div>
</template>

<script>
import TeamInformation from '@/views/team-management/components/TeamInformation'
import PlayerInformation from '@/views/team-management/components/PlayerInformation'
import OperationButton from '@/views/team-management/team-register/components/OperationButton'
import { saveUpdate } from '@/api/team'

export default {
  name: 'TeamRegister',
  components: { OperationButton, PlayerInformation, TeamInformation },
  data() {
    return {
      form: { reg_status: 0 },
      list: [
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 },
        { p_name: '', st_id: '', p_number: '', is_insurance: 1 }
      ]
    }
  },
  methods: {
    handleReset() {
      this.$refs.form.form = {}
      this.$refs.table.list = []
    },
    handleSubmit() {
      const form = this.$refs.form.form
      const list = this.$refs.table.list
      saveUpdate({ team: form, player: list }).then(response => {
        const { data } = response
        this.$message.info(data)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .app-container {
    .roles-table {
      margin-top: 30px;
    }

    .permission-tree {
      margin-bottom: 30px;
    }
  }
</style>
